#include "FloatTestEnvironment.h"
#include "FloatChromosomeFactory.h"
#include "Chromosome.h"

FloatTestEnvironment::FloatTestEnvironment(int _populationSize,
                                 int chromosomeLength) :
                    AbstractEnvironment(_populationSize)
{
    setBestFitness(chromosomeLength);

    chromosomeFactory = new FloatChromosomeFactory(chromosomeLength);
    //createPopulation();
}

void FloatTestEnvironment::fitnessFunction(Chromosome& chrom)
{
    double fitness = 0.0;

    for(int i=0;i<chrom.size();++i)
    {
        if( (i%2==0 && (chrom.at(i).toDouble() < -500.0)) ||
            (i%2==1 && (chrom.at(i).toDouble() > 500.0)) )
            fitness += 1.0;
    }
    chrom.setFitness(fitness);
}
